package ciarlini.utils;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

public class VisaoUtils {
    public static void exibePopUpErro(Throwable ex) {
        JDialog dialog = criaDialog("Erro!", ex.getMessage());
        dialog.setVisible(true);
    }

    public static void exibePopUpInformacao(String msg) {
        JDialog dialog = criaDialog("INFO", msg);
        dialog.setVisible(true);
    }
    
    private static JDialog criaDialog(String titulo, String mensagem) {
        final JDialog dialog = new JDialog();
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setLayout(new GridLayout(2,1));
        dialog.setSize(300, 150);
        dialog.setModal(true);
        dialog.setTitle(titulo);
        JLabel label = new JLabel(mensagem);
        JButton botaoFechar = new JButton("Fechar");
        dialog.add(label);
        dialog.add(botaoFechar);
        botaoFechar.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        });
        return dialog;
        
    }

}
